package com.example.springbootapplication;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Author acy
 * @Date 2019/04/27
 */
public class SpringApplicationEventBootstrap {
	public static void main(String[] args) {
		//创建上下文，这个上下文是非WEB上下文
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

		//注册应用事件监听器
		context.addApplicationListener((event)->{
			System.out.println("监听到事件"+event);
		});
		//启动上下文
		context.refresh();

		context.publishEvent("发布事件 hello world");

		context.publishEvent(new ApplicationEvent("hello world") {
		});
		//关闭上下文
		context.close();
	}
}
